<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加会员</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__CSS__/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__CSS__/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__CSS__/animate.min.css" rel="stylesheet">
    <link href="__CSS__/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="__CSS__/style.min.css?v=4.1.0" rel="stylesheet">
    <link href="__JS__/plugins/bootstrap-tagsinput/bootstrap-tagsinput.css" rel="stylesheet">
    <link href="__JS__/layui/css/layui.css" rel="stylesheet">
    <style>
        .file {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
        }

        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }

        .file:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: none;
        }
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-10">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加会员</h5>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="commentForm" method="post" action="{:url('User/add')}">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">用户名：</label>
                            <div class="input-group col-sm-7">
                                <input id="username" type="text" class="form-control" name="username" required=""
                                       aria-required="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">性别：</label>
                            <div class="input-group col-sm-6">
                                {foreach name='status' item='vo' key='key'}
                                <div class="radio i-checks col-sm-4">
                                    <label>
                                        <input type="radio" value="{$key}" {if condition="$key == 1 " }checked{/if}
                                        name="sex"> <i></i> {$vo}</label>
                                </div>
                                {/foreach}
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否推荐：</label>
                            <div class="input-group col-sm-6">
                                {foreach name='restatus' item='vo' key='key'}
                                <div class="radio i-checks col-sm-4">
                                    <label>
                                        <input type="radio" value="{$key}" {if condition="$key == 0 " }checked{/if}
                                        name="is_recommend"> <i></i> {$vo}</label>
                                </div>
                                {/foreach}
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否推荐：</label>
                            <div class="input-group col-sm-6">
                                {foreach name='isfew' item='vo' key='key'}
                                <div class="radio i-checks col-sm-4">
                                    <label>
                                        <input type="radio" value="{$key}" {if condition="$key == 0 " }checked{/if}
                                        name="isfew"> <i></i> {$vo}</label>
                                </div>
                                {/foreach}
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">首页显示：</label>
                            <div class="input-group col-sm-6">
                                {foreach name='is_show' item='vo' key='key'}
                                <div class="radio i-checks col-sm-4">
                                    <label>
                                        <input type="radio" value="{$key}" {if condition="$key == 0 " }checked{/if}
                                        name="is_show"> <i></i> {$vo}</label>
                                </div>
                                {/foreach}
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">年龄：</label>
                            <div class="input-group col-sm-7">
                                <input id="age" type="text" class="form-control" name="age" required=""
                                       aria-required="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">手机号：</label>
                            <div class="input-group col-sm-7">
                                <input id="phone" type="text" class="form-control" name="phone" required=""
                                       aria-required="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">自我介绍：</label>
                            <div class="input-group col-sm-7">
                                <textarea id="selfintro" class="form-control" name="selfintro" required=""
                                          aria-required="true"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">头像：</label>
                            <input name="url" id="thumbnail" type="hidden"/>
                            <div class="form-inline">
                                <div class="input-group col-sm-2">
                                    <button type="button" class="layui-btn" id="test1">
                                        <i class="layui-icon">&#xe67c;</i>上传头像
                                    </button>
                                </div>
                                <div class="input-group col-sm-3">
                                    <div id="sm"></div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">视频封面：</label>
                            <input name="cover_url" id="cover_url" type="hidden"/>
                            <div class="form-inline">
                                <div class="input-group col-sm-2">
                                    <button type="button" class="layui-btn" id="test_cover">
                                        <i class="layui-icon">&#xe67c;</i>上传封面
                                    </button>
                                </div>
                                <div class="input-group col-sm-3">
                                    <div id="sm_cover"></div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">视频：</label>
                            <input name="video_url" id="video" type="hidden"/>
                            <div class="form-inline">
                                <div class="input-group col-sm-2">
                                    <a href="javascript:;" class="file">选择视频
                                        <input type="file" name="files" class="upinput" param1="xxx">
                                    </a>

                                    <input type="hidden" name="video_url" value="" class="param2">
                                </div>
                                <div class="input-group col-sm-3">
                                    <div id="video_show"></div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">视频描述：</label>
                            <div class="input-group col-sm-7">
                                <textarea id="video_desc" class="form-control" name="video_desc" required=""
                                          aria-required="true"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-8">
                                <button class="btn btn-primary" type="submit">确认提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
<script src="__JS__/jquery.min.js?v=2.1.4"></script>
<script src="__JS__/bootstrap.min.js?v=3.3.6"></script>
<script src="__JS__/content.min.js?v=1.0.0"></script>
<script src="__JS__/plugins/bootstrap-tagsinput/bootstrap-tagsinput.min.js"></script>
<script src="__JS__/plugins/validate/jquery.validate.min.js"></script>
<script src="__JS__/plugins/validate/messages_zh.min.js"></script>
<script src="__JS__/plugins/iCheck/icheck.min.js"></script>
<script src="__JS__/layui/layui.js"></script>
<script src="__JS__/jquery.form.js"></script>
<script src="__JS__/plugins/ueditor/ueditor.config.js"></script>
<script src="__JS__/plugins/ueditor/ueditor.all.js"></script>
<script src="__JS__/jquery.ui.widget.js"></script>
<script src="__JS__/jquery.iframe-transport.js"></script>
<script src="__JS__/jquery.fileupload.js"></script>
<script type="text/javascript">

    var index = '';

    function showStart() {
        index = layer.load(0, {shade: false});
        return true;
    }

    function showSuccess(res) {

        layer.ready(function () {
            layer.close(index);
            if (1 == res.code) {
                layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function () {
                    window.location.href = res.data;
                });
            } else if (111 == res.code) {
                window.location.reload();
            } else {
                layer.msg(res.msg, {anim: 6});
            }
        });
    }

    $(document).ready(function () {
        $(".i-checks").iCheck({checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green",});
        // 添加角色
        var options = {
            beforeSubmit: showStart,
            success: showSuccess
        };

        $('#commentForm').submit(function () {
            $(this).ajaxSubmit(options);
            return false;
        });

        $('#keywords').tagsinput('add', 'some tag');
        $(".bootstrap-tagsinput").addClass('col-sm-12').find('input').addClass('form-control')
            .attr('placeholder', '输入后按enter');

        // 上传图片
        layui.use('upload', function () {
            var upload = layui.upload;

            //执行头像
            var uploadInst = upload.render({
                elem: '#test1' //绑定元素
                , method: "post"
                , data: {
                    'user_cover': 0
                }
                , url: "{:url('User/uploadImg')}" //上传接口
                , done: function (res) {
                    //上传完毕回调
                    $("#thumbnail").val(res.data.src);
                    $("#sm").html('<img src="' + res.data.src + '" style="width:40px;height: 40px;"/>');
                }
                , error: function () {
                    //请求异常回调
                }
            });
            //执行视频封面
            var uploadInst = upload.render({
                elem: '#test_cover' //绑定元素
                , url: "{:url('User/uploadImg')}" //上传接口
                , method: "post"
                , data: {
                    'video_cover': 1
                },
                done: function (res) {
                    //上传完毕回调
                    $("#cover_url").val(res.data.src);
                    $("#sm_cover").html('<img src="' + res.data.src + '" style="width:40px;height: 40px;"/>');
                }
                , error: function () {
                    //请求异常回调
                }
            });
        });

    });

    // 表单验证
    $.validator.setDefaults({
        highlight: function (e) {
            $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
        },
        success: function (e) {
            e.closest(".form-group").removeClass("has-error").addClass("has-success")
        },
        errorElement: "span",
        errorPlacement: function (e, r) {
            e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
        },
        errorClass: "help-block m-b-none",
        validClass: "help-block m-b-none"
    });
</script>
<script>
    $(".upinput").fileupload({
        url: "{:url('User/video')}",//文件上传地址，当然也可以直接写在input的data-url属性内
        dataType: "json", //如果不指定json类型，则传来的json字符串就需要解析jQuery.parseJSON(data.result);
        formData: function (form) {
            return [{name: "param1", value: $(".upinput").attr("param1")},
                {name: "param2", value: $(".param2").val()}];
        },
        done: function (e, data) {
            //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
            //注意data要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
            //返回的数据在data.result中，这里dataType中设置的返回的数据类型为json
            if (data.result.sta) {
                // 上传成功：
                $(".upstatus").html(data.result.msg);
                $(".param2").val(data.result.previewSrc);
                $("#video_show").html("<embed src=" + data.result.previewSrc +
                    " allowscriptaccess='always' allowfullscreen='true' wmode='opaque'" +
                    " width='120' height='120'></embed>");
            } else {
                // 上传失败：
                $(".progress .bar").css("width", "0%");
                $(".upstatus").html("<span style='color:red;'>" + data.result.msg + "</span>");
            }

        },
        progress: function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $(".progress .bar").css("width", progress + "%");
            $(".upstatus").html("正在上传...");
        },
    });
</script>
</body>
</html>
